import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_screenutil/screen_util.dart';
import 'package:provider/provider.dart';
import 'package:study_online/entity/Student.dart';
import 'package:study_online/global/colors.dart';

import 'package:flutter/material.dart';
import 'package:study_online/global/global.dart';

import '../MyViewModel.dart';
import 'DialogsPage.dart';

void main() {
  runApp(
    MultiProvider(
      providers: [
        ChangeNotifierProvider(create: (_) => (MyViewModel())),
      ],
      child: MyApp(),
    ),
  );
}

class MyApp extends StatelessWidget {
  const MyApp({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      builder: EasyLoading.init(),
      home: Scaffold(
        //appBar: AppBar(
        //  backgroundColor: Colors.black26,
        //  title: Text('container'),
        //),
        body: UserInformationPage(),
      ),
    );
  }
}

class UserInformationPage extends StatefulWidget {
  UserInformationPage({Key key}) : super(key: key);

  @override
  _UserInformationPageState createState() {
    return _UserInformationPageState();
  }
}

class _UserInformationPageState extends State<UserInformationPage> {
  Student _student = new Student(
      '201901020121',
      '吕浩',
      '11',
      '计算机科学与技术',
      '男',
      'https://img2.baidu.com/it/u=1915681330,636879278&fm=26&fmt=auto',
      100,
      '15344425756');

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    //debugPaintSizeEnabled=true;
    ScreenUtil.init(
      BoxConstraints(
          maxWidth: MediaQuery.of(context).size.width,
          maxHeight: MediaQuery.of(context).size.height),
      designSize: Size(1080, 2340),
    );
    return Scaffold(
      appBar: AppBar(
        title: Text(
          '个人资料',
          style: TextStyle(
            fontSize: ScreenUtil().setSp(53),
            color: Colors.black,
          ),
        ),
        elevation: 0,
        backgroundColor: Colors.white,
        leading: IconButton(
          icon: Icon(Icons.arrow_back, color: Colors.black),
          onPressed: () {
            Provider.of<MyViewModel>(context,listen: false).updateUser();
            //Navigator.pop(context);
          },
        ),
      ),
      body: Container(
        color: AppColors.pageBackground,
        child: Column(
          children: [
            _headImgWidget(),
            _nameWidget(),
            _stuIdWidget(),
            _instituteWidget(),
            _majorWidget(),
            _birthDayWidget(),
            _telWidget(),
            _QQWidget(),
            _weChatWidget()
          ],
        ),
      ),
    );
  }

  _headImgWidget() {
    return Column(
      children: [
        Container(
          width: ScreenUtil().screenWidth,
          height: ScreenUtil().setHeight(160),
          color: Colors.white,
          padding: EdgeInsets.fromLTRB(
            ScreenUtil().setWidth(52),
            ScreenUtil().setHeight(0),
            ScreenUtil().setWidth(0),
            ScreenUtil().setHeight(0),
          ),
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Text(
                '头像',
                style: TextStyle(
                  fontSize: ScreenUtil().setSp(50),
                  color: Colors.black,
                ),
              ),
              Expanded(
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.end,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    Builder(builder: (_) {
                      if (Provider.of<MyViewModel>(context, listen: false)
                              .image ==
                          null) {
                        return ClipOval(
                          child: Image.network(
                            Provider.of<MyViewModel>(context, listen: false)
                                .student
                                .photo,
                            width: ScreenUtil().setHeight(122),
                            height: ScreenUtil().setHeight(122),
                            fit: BoxFit.cover,
                          ),
                        );
                      } else {
                        return ClipOval(
                          child: Image.file(
                            Provider.of<MyViewModel>(context, listen: false)
                                .image,
                            width: ScreenUtil().setHeight(122),
                            height: ScreenUtil().setHeight(122),
                            fit: BoxFit.cover,
                          ),
                        );
                      }
                    }),
                    IconButton(
                      icon: Icon(Icons.arrow_forward_ios_rounded,
                          color: Colors.black),
                      onPressed: () {
                        showImgDialog(context);
                      },
                    )
                  ],
                ),
              ),
            ],
          ),
        ),
        Container(
          width: ScreenUtil().screenWidth - ScreenUtil().setWidth(104),
          height: 0.5,
          padding: EdgeInsets.fromLTRB(
            ScreenUtil().setWidth(52),
            ScreenUtil().setHeight(0),
            ScreenUtil().setWidth(52),
            ScreenUtil().setHeight(0),
          ),
          color: Colors.black12,
        ),
      ],
    );
  }

  _stuIdWidget() {
    return Column(
      children: [
        Container(
          width: ScreenUtil().screenWidth,
          height: ScreenUtil().setHeight(160),
          color: Colors.white,
          padding: EdgeInsets.fromLTRB(
            ScreenUtil().setWidth(52),
            ScreenUtil().setHeight(0),
            ScreenUtil().setWidth(0),
            ScreenUtil().setHeight(0),
          ),
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Text(
                '学号',
                style: TextStyle(
                  fontSize: ScreenUtil().setSp(50),
                  color: Colors.black,
                ),
              ),
              Expanded(
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.end,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    Text(
                      Provider.of<MyViewModel>(context, listen: false)
                          .student
                          .stuId,
                      style: TextStyle(
                        fontSize: ScreenUtil().setSp(50),
                        color: Colors.black45,
                      ),
                    ),
                    IconButton(
                      icon: Icon(Icons.arrow_forward_ios_rounded,
                          color: Colors.black45),
                      onPressed: () {},
                    )
                  ],
                ),
              ),
            ],
          ),
        ),
        Container(
          width: ScreenUtil().screenWidth - ScreenUtil().setWidth(104),
          height: 0.5,
          padding: EdgeInsets.fromLTRB(
            ScreenUtil().setWidth(52),
            ScreenUtil().setHeight(0),
            ScreenUtil().setWidth(52),
            ScreenUtil().setHeight(0),
          ),
          color: Colors.black12,
        ),
      ],
    );
  }

  _majorWidget() {
    return Container(
      width: ScreenUtil().screenWidth,
      height: ScreenUtil().setHeight(160),
      padding: EdgeInsets.fromLTRB(
        ScreenUtil().setWidth(52),
        ScreenUtil().setHeight(0),
        ScreenUtil().setWidth(0),
        ScreenUtil().setHeight(0),
      ),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.only(
            bottomLeft: Radius.circular(18), bottomRight: Radius.circular(18)),
      ),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          Text(
            '专业',
            style: TextStyle(
              fontSize: ScreenUtil().setSp(50),
              color: Colors.black,
            ),
          ),
          Expanded(
            child: Row(
              mainAxisAlignment: MainAxisAlignment.end,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Text(
                  Provider.of<MyViewModel>(context).student.major,
                  style: TextStyle(
                    fontSize: ScreenUtil().setSp(50),
                    color: Colors.black,
                  ),
                ),
                IconButton(
                  icon: Icon(Icons.arrow_forward_ios_rounded,
                      color: Colors.black),
                  onPressed: () {
                    showDialog(
                      context: context,
                      builder: (BuildContext context) {
                        return InputDialog1(
                          content: '专业名称',
                        );
                      },
                      barrierDismissible: false,
                    );
                  },
                )
              ],
            ),
          ),
        ],
      ),
    );
  }

  _instituteWidget() {
    return Column(
      children: [
        Container(
          width: ScreenUtil().screenWidth,
          height: ScreenUtil().setHeight(160),
          color: Colors.white,
          padding: EdgeInsets.fromLTRB(
            ScreenUtil().setWidth(52),
            ScreenUtil().setHeight(0),
            ScreenUtil().setWidth(0),
            ScreenUtil().setHeight(0),
          ),
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Text(
                '学院',
                style: TextStyle(
                  fontSize: ScreenUtil().setSp(50),
                  color: Colors.black,
                ),
              ),
              Expanded(
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.end,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    Text(
                      Provider.of<MyViewModel>(context).student.major,
                      style: TextStyle(
                        fontSize: ScreenUtil().setSp(50),
                        color: Colors.black,
                      ),
                    ),
                    IconButton(
                      icon: Icon(Icons.arrow_forward_ios_rounded,
                          color: Colors.black),
                      onPressed: () {
                        showDialog(
                          context: context,
                          builder: (BuildContext context) {
                            return InputDialog1(
                              content: '学院名称',
                            );
                          },
                          barrierDismissible: false,
                        );
                      },
                    )
                  ],
                ),
              ),
            ],
          ),
        ),
        Container(
          width: ScreenUtil().screenWidth - ScreenUtil().setWidth(104),
          height: 0.5,
          padding: EdgeInsets.fromLTRB(
            ScreenUtil().setWidth(52),
            ScreenUtil().setHeight(0),
            ScreenUtil().setWidth(52),
            ScreenUtil().setHeight(0),
          ),
          color: Colors.black12,
        ),
      ],
    );
  }

  _nameWidget() {
    return Column(
      children: [
        Container(
          width: ScreenUtil().screenWidth,
          height: ScreenUtil().setHeight(160),
          color: Colors.white,
          padding: EdgeInsets.fromLTRB(
            ScreenUtil().setWidth(52),
            ScreenUtil().setHeight(0),
            ScreenUtil().setWidth(0),
            ScreenUtil().setHeight(0),
          ),
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Text(
                '姓名',
                style: TextStyle(
                  fontSize: ScreenUtil().setSp(50),
                  color: Colors.black,
                ),
              ),
              Expanded(
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.end,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    Text(
                      _student.name,
                      style: TextStyle(
                        fontSize: ScreenUtil().setSp(50),
                        color: Colors.black,
                      ),
                    ),
                    IconButton(
                      icon: Icon(Icons.arrow_forward_ios_rounded,
                          color: Colors.black),
                      onPressed: () {
                        showDialog(
                          context: context,
                          builder: (BuildContext context) {
                            return InputDialog1(
                              content: '姓名',
                            );
                          },
                          barrierDismissible: false,
                        );
                      },
                    )
                  ],
                ),
              ),
            ],
          ),
        ),
        Container(
          width: ScreenUtil().screenWidth - ScreenUtil().setWidth(104),
          height: 0.5,
          padding: EdgeInsets.fromLTRB(
            ScreenUtil().setWidth(52),
            ScreenUtil().setHeight(0),
            ScreenUtil().setWidth(52),
            ScreenUtil().setHeight(0),
          ),
          color: Colors.black12,
        ),
      ],
    );
  }

  _telWidget() {
    return Column(
      children: [
        Container(
          width: ScreenUtil().screenWidth,
          height: ScreenUtil().setHeight(160),
          color: Colors.white,
          padding: EdgeInsets.fromLTRB(
            ScreenUtil().setWidth(52),
            ScreenUtil().setHeight(0),
            ScreenUtil().setWidth(0),
            ScreenUtil().setHeight(0),
          ),
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Text(
                '手机号',
                style: TextStyle(
                  fontSize: ScreenUtil().setSp(50),
                  color: Colors.black,
                ),
              ),
              Expanded(
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.end,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    Text(
                      Provider.of<MyViewModel>(context, listen: false)
                          .student
                          .phone,
                      style: TextStyle(
                        fontSize: ScreenUtil().setSp(50),
                        color: Colors.black,
                      ),
                    ),
                    IconButton(
                      icon: Icon(Icons.arrow_forward_ios_rounded,
                          color: Colors.black),
                      onPressed: () {
                        showDialog(
                          context: context,
                          builder: (BuildContext context) {
                            return InputDialog1(
                              content: '手机号',
                            );
                          },
                          barrierDismissible: false,
                        );
                      },
                    )
                  ],
                ),
              ),
            ],
          ),
        ),
        Container(
          width: ScreenUtil().screenWidth - ScreenUtil().setWidth(104),
          height: 0.5,
          padding: EdgeInsets.fromLTRB(
            ScreenUtil().setWidth(52),
            ScreenUtil().setHeight(0),
            ScreenUtil().setWidth(52),
            ScreenUtil().setHeight(0),
          ),
          color: Colors.black12,
        ),
      ],
    );
  }

  _QQWidget() {
    return Column(
      children: [
        Container(
          width: ScreenUtil().screenWidth,
          height: ScreenUtil().setHeight(160),
          color: Colors.white,
          padding: EdgeInsets.fromLTRB(
            ScreenUtil().setWidth(52),
            ScreenUtil().setHeight(0),
            ScreenUtil().setWidth(0),
            ScreenUtil().setHeight(0),
          ),
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Text(
                'QQ号码',
                style: TextStyle(
                  fontSize: ScreenUtil().setSp(50),
                  color: Colors.black,
                ),
              ),
              Expanded(
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.end,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    Text(
                      Provider.of<MyViewModel>(context, listen: false).qq,
                      style: TextStyle(
                        fontSize: ScreenUtil().setSp(50),
                        color: Provider.of<MyViewModel>(context, listen: false)
                                    .qq ==
                                '待完善'
                            ? AppColors.primary
                            : Colors.black,
                      ),
                    ),
                    IconButton(
                      icon: Icon(Icons.arrow_forward_ios_rounded,
                          color: Colors.black),
                      onPressed: () {
                        showDialog(
                          context: context,
                          builder: (BuildContext context) {
                            return InputDialog1(
                              content: 'QQ号',
                            );
                          },
                          barrierDismissible: false,
                        );
                      },
                    ),
                  ],
                ),
              ),
            ],
          ),
        ),
        Container(
          width: ScreenUtil().screenWidth - ScreenUtil().setWidth(104),
          height: 0.5,
          padding: EdgeInsets.fromLTRB(
            ScreenUtil().setWidth(52),
            ScreenUtil().setHeight(0),
            ScreenUtil().setWidth(52),
            ScreenUtil().setHeight(0),
          ),
          color: Colors.black12,
        ),
      ],
    );
  }

  _weChatWidget() {
    return Column(
      children: [
        Container(
          width: ScreenUtil().screenWidth,
          height: ScreenUtil().setHeight(160),
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.only(
                bottomLeft: Radius.circular(18),
                bottomRight: Radius.circular(18)),
          ),
          padding: EdgeInsets.fromLTRB(
            ScreenUtil().setWidth(52),
            ScreenUtil().setHeight(0),
            ScreenUtil().setWidth(0),
            ScreenUtil().setHeight(0),
          ),
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Text(
                '微信号',
                style: TextStyle(
                  fontSize: ScreenUtil().setSp(50),
                  color: Colors.black,
                ),
              ),
              Expanded(
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.end,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    Text(
                      Provider.of<MyViewModel>(context, listen: false).weChat,
                      style: TextStyle(
                        fontSize: ScreenUtil().setSp(50),
                        color: Provider.of<MyViewModel>(context, listen: false)
                                    .weChat ==
                                '待完善'
                            ? AppColors.primary
                            : Colors.black,
                      ),
                    ),
                    IconButton(
                      icon: Icon(Icons.arrow_forward_ios_rounded,
                          color: Colors.black),
                      onPressed: () {
                        showDialog(
                          context: context,
                          builder: (BuildContext context) {
                            return InputDialog1(
                              content: '微信号',
                            );
                          },
                          barrierDismissible: false,
                        );
                      },
                    ),
                  ],
                ),
              ),
            ],
          ),
        ),
        Container(
          width: ScreenUtil().screenWidth - ScreenUtil().setWidth(104),
          height: 0.5,
          padding: EdgeInsets.fromLTRB(
            ScreenUtil().setWidth(52),
            ScreenUtil().setHeight(0),
            ScreenUtil().setWidth(52),
            ScreenUtil().setHeight(0),
          ),
          color: Colors.black12,
        ),
      ],
    );
  }

  _birthDayWidget() {
    return Column(
      children: [
        SizedBox(height: ScreenUtil().setHeight(40)),
        Container(
          width: ScreenUtil().screenWidth,
          height: ScreenUtil().setHeight(160),
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.only(
                topLeft: Radius.circular(18), topRight: Radius.circular(18)),
          ),
          padding: EdgeInsets.fromLTRB(
            ScreenUtil().setWidth(52),
            ScreenUtil().setHeight(0),
            ScreenUtil().setWidth(0),
            ScreenUtil().setHeight(0),
          ),
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Text(
                '生日',
                style: TextStyle(
                  fontSize: ScreenUtil().setSp(50),
                  color: Colors.black,
                ),
              ),
              Expanded(
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.end,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    Text(
                      Provider.of<MyViewModel>(context, listen: false).birthDay,
                      style: TextStyle(
                        fontSize: ScreenUtil().setSp(50),
                        color: Provider.of<MyViewModel>(context, listen: false)
                                    .birthDay ==
                                '待完善'
                            ? AppColors.primary
                            : Colors.black,
                      ),
                    ),
                    IconButton(
                      icon: Icon(Icons.arrow_forward_ios_rounded,
                          color: Colors.black),
                      onPressed: () {
                        showDataDialog(context);
                      },
                    ),
                  ],
                ),
              ),
            ],
          ),
        ),
        Container(
          width: ScreenUtil().screenWidth - ScreenUtil().setWidth(104),
          height: 0.5,
          padding: EdgeInsets.fromLTRB(
            ScreenUtil().setWidth(52),
            ScreenUtil().setHeight(0),
            ScreenUtil().setWidth(52),
            ScreenUtil().setHeight(0),
          ),
          color: Colors.black12,
        ),
      ],
    );
  }
}
